package com.yanqu.road.server.cmd.activity.dafuweng.zaoyao;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.monopoly.MonopolyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.dafuweng.DaFuWengMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_DA_FU_WENG_USE_CARD_ZAO_YAO, desc = "使用造谣卡造谣")
public class DaFuWengUseCardZaoYaoCmd extends AbstractCommand {
    private int index;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MonopolyProto.UseCardZaoYaoReqMsg msg = MonopolyProto.UseCardZaoYaoReqMsg.parseFrom(packet.getBytes());
        index = msg.getIndex();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = DaFuWengMgr.checkGroup(player.getUserId());
        if (ret != 0) {
            return;
        }

        DaFuWengMgr.useCardZaoYao(index, player);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            MonopolyProto.UseCardZaoYaoRespMsg.Builder respMsg = MonopolyProto.UseCardZaoYaoRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_DA_FU_WENG_USE_CARD_ZAO_YAO, respMsg);
        }
    }
}
